var app = angular.module('dataCollectionApp',['ngResource', 'ngRoute','controllers','directives','ui.router'], function ($httpProvider) {
    // Use x-www-form-urlencoded Content-Type
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

    /**
     * The workhorse; converts an object to x-www-form-urlencoded serialization.
     * @param {Object} obj
     * @return {String}
     */
     
    var param = function (_obj) {
        var paramData = '', name, value, fullSubName, subName, subValue, innerObj, i;
        add = function(obj){
        	var query = "";
        	for (name in obj) {
                value = obj[name];

                if (value instanceof Array) {
                    for (i = 0; i < value.length; ++i) {
                        subValue = value[i];
                        fullSubName = name + '[' + i + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                }
                else if (value instanceof Object) {
                    for (subName in value) {
                        subValue = value[subName];
                        fullSubName = name + '[' + subName + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                }
                else if (value !== undefined && value !== null)
                    query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
            }
             return  query;
        }
        if(_obj instanceof Array){
        	 for (i = 0; i < _obj.length; ++i) {
        		
        		 paramData+=add(_obj[i]);
        	 }
        }else{
        	paramData+=add(_obj)
        }
        return  paramData.length ? paramData.substr(0, paramData.length - 1) : paramData;
    };

    // Override $http service's default transformRequest
    $httpProvider.defaults.transformRequest = [function (data) {
        return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
    }];
});
/*
app.config(['$routeProvider', function($routeProvider){
	$routeProvider.when('/room/roomList',{
		templateUrl:'/pages/room/roomList.html',
		controller:'roomCtrl'
	})
	.otherwise({redirectTo:'/'});
}]);
*/

/**
 * 路由
 */
app.config(['$stateProvider', '$urlRouterProvider',function ($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/');
    var templateUrl = '/pages/home.html';
    $stateProvider.state("/", {
        url: "/",
        templateUrl: '/pages/suppliesManage/suppliesManage.html'
    }).state('suppliesManage', {
        url: "/suppliesManage",
        templateUrl: '/pages/suppliesManage/suppliesManage.html'
    }).state('suppliesManage.contractmain', {
        url: '/contracttemplate',
        //templateUrl: '/pages/contract/contractmain.html',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/contracttemplate/contractmain.html'  //合同测试管理
            }
        }
    }).state('suppliesManage.projectDefinition', {
        url: '/projectDefinition',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/contracttemplate/projectDefinition.html'  //项目管理
            }
        }
    }).state('suppliesManage.contractTemplateTest', {
            url: '/contractTemplateTest',
            views:{
                'suppliesManageView':{
                    templateUrl: '/pages/contracttemplate/contractTemplateTest.html'  //合同模板测试
                }
            }
    }).state('suppliesManage.contractVarValuePoolAdd', {
        url: '/contractVarValuePoolAdd',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/contractvarpool/contractVarValuePoolAdd.html'  //项目管理
            }
        }
    }).state('suppliesManage.contractVarValuePoolList', {
        url: '/contractVarValuePoolList',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/contractvarpool/contractVarValuePoolList.html'  //变量管理
            }
        }
    }).state('suppliesManage.contractTemplateList', {
        url: '/contractTemplateList',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/contracttemplate/contractTemplateList.html'  //合同模板管理
            }
        }
    }).state('suppliesManage.contractinfo', {
        url: '/contractinfo',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/contract/contractinfo.html'  //合同查询
            }
        }
    }).state('suppliesManage.companyauth', {
        url: '/companyauth',
        views:{
            'suppliesManageView':{
                templateUrl: '/pages/companyauth/companyauth.html'  //公司认证列表
            }
        }
    })


}]);
